package cn.ecnu.service.forum.impl;

import cn.ecnu.mapper.forum.PostMapper;
import cn.ecnu.pojo.forum.Post;
import cn.ecnu.service.forum.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {

    @Resource
    private PostMapper postMapper;

    @Override
    public int insertPost(Post post) {
        post.setLikeCount(0); post.setCommentCount(0);
        post.setHot(0); post.setReview(1); // TODO: 直接过审
        return postMapper.insertPost(post);
    }

    @Override
    public int deletePostById(Integer postId) {
        return postMapper.deletePostById(postId);
    }

    @Override
    public int updatePostById(Post post) {
        return postMapper.updatePostById(post);
    }

    @Override
    public Post getPostById(Integer postId) {
        // TODO 需要和User整合
        return postMapper.getPostById(postId);
    }

    @Override
    public List<Post> getPostByForumId(Integer forumId) {
        // TODO: 需要和User整合
        return postMapper.getPostByForumId(forumId);
    }

    @Override
    public List<Post> getPostByUserId(Integer userId) {
        // TODO: 需要和User整合
        return postMapper.getPostByUserId(userId);
    }

    @Override
    public List<Post> getPostByForumIdUsePag(Integer forumId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByForumIdUsePage(forumId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByUserIdUserPage(Integer forumId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByUserIdUserPage(forumId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByForumIdUsePageOrderByTime(Integer forumId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByForumIdUsePageOrderByTime(forumId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByForumIdUsePageOrderByHot(Integer forumId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByForumIdUsePageOrderByHot(forumId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByUserIdUsePageOrderByTime(Integer userId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByUserIdUsePageOrderByTime(userId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByUserIdUsePageOrderByHot(Integer userId, Integer pageNum, Integer pageSize) {
        return postMapper.getPostByUserIdUsePageOrderByHot(userId, (pageNum - 1) * pageSize , pageSize);
    }

    @Override
    public List<Post> getPostByTagsAndContent(String keyword) {
        return postMapper.getPostByTagsAndContent(keyword);
    }
}
